package com.kld.yqyj.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kld.common.annotation.Log;
import com.kld.common.annotation.RepeatSubmit;
import com.kld.common.core.controller.BaseController;
import com.kld.common.core.domain.PageQuery;
import com.kld.common.core.domain.R;
import com.kld.common.core.page.TableDataInfo;
import com.kld.common.core.validate.AddGroup;
import com.kld.common.core.validate.EditGroup;
import com.kld.common.core.validate.QueryGroup;
import com.kld.common.enums.BusinessType;
import com.kld.common.utils.poi.ExcelUtil;
import com.kld.yqyj.domain.bo.TDzGldyCurInforBo;
import com.kld.yqyj.domain.vo.TDzGldyCurInforVo;
import com.kld.yqyj.service.ITDzGldyCurInforService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 管理单元基础信息Controller
 *
 * @author bw
 * @date 2024-05-15
 */
@Validated
@Api(value = "管理单元基础信息控制器", tags = {"管理单元基础信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/yqyj/dzGldyCurInfor")
public class TDzGldyCurInforController extends BaseController {

    private final ITDzGldyCurInforService iTDzGldyCurInforService;

    /**
     * 查询管理单元基础信息列表
     */
    @ApiOperation("查询管理单元基础信息列表")
    @SaCheckPermission("yqyj:dzGldyCurInfor:list")
    @GetMapping("/list")
    public TableDataInfo<TDzGldyCurInforVo> list(@Validated(QueryGroup.class) TDzGldyCurInforBo bo, PageQuery pageQuery) {
        return iTDzGldyCurInforService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出管理单元基础信息列表
     */
    @ApiOperation("导出管理单元基础信息列表")
    @SaCheckPermission("yqyj:dzGldyCurInfor:export")
    @Log(title = "管理单元基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TDzGldyCurInforBo bo, HttpServletResponse response) {
        List<TDzGldyCurInforVo> list = iTDzGldyCurInforService.queryList(bo);
        ExcelUtil.exportExcel(list, "管理单元基础信息", TDzGldyCurInforVo.class, response);
    }

    /**
     * 获取管理单元基础信息详细信息
     */
    @ApiOperation("获取管理单元基础信息详细信息")
    @SaCheckPermission("yqyj:dzGldyCurInfor:query")
    @GetMapping("/{jcId}")
    public R<TDzGldyCurInforVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("jcId") String jcId) {
        return R.ok(iTDzGldyCurInforService.queryById(jcId));
    }

    /**
     * 新增管理单元基础信息
     */
    @ApiOperation("新增管理单元基础信息")
    @SaCheckPermission("yqyj:dzGldyCurInfor:add")
    @Log(title = "管理单元基础信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TDzGldyCurInforBo bo) {
        return toAjax(iTDzGldyCurInforService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改管理单元基础信息
     */
    @ApiOperation("修改管理单元基础信息")
    @SaCheckPermission("yqyj:dzGldyCurInfor:edit")
    @Log(title = "管理单元基础信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TDzGldyCurInforBo bo) {
        return toAjax(iTDzGldyCurInforService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除管理单元基础信息
     */
    @ApiOperation("删除管理单元基础信息")
    @SaCheckPermission("yqyj:dzGldyCurInfor:remove")
    @Log(title = "管理单元基础信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jcIds}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] jcIds) {
        return toAjax(iTDzGldyCurInforService.deleteWithValidByIds(Arrays.asList(jcIds), true) ? 1 : 0);
    }
}
